package com.xiang.plane.activity;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Bundle;
import android.util.LruCache;
import android.view.Window;
import android.view.WindowManager;

import com.xiang.plane.R;
import com.xiang.plane.util.ImageUtil;
import com.xiang.plane.view.GameView;
import com.xiang.plane.view.TestGlSurfaceView;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //无title
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //全屏
        getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,
                WindowManager.LayoutParams. FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
        GameView gameView = new GameView(MainActivity.this);
        setContentView(gameView);
        init();
    }

    /**
     * 初始化
     */
    private void init() {
        /**
         * 初始化图片缓存
         */
        //得到程序能得到的最大内存
        long maxMemory = Runtime.getRuntime().maxMemory();
        int cacheMemory = (int) (maxMemory / 8);
        ImageUtil.ImageCacahe = new LruCache<>(cacheMemory);
        //加载图片资源
        loadImageRes();
    }


    //加载图片资源
    private void loadImageRes() {
        Resources resources = getResources();
        Bitmap tmp;
        //加载敌机
        tmp = BitmapFactory.decodeResource(resources, R.drawable.enemy01);
        ImageUtil.ImageCacahe.put(ImageUtil.ENEMY_1_KEY, tmp);
        tmp = BitmapFactory.decodeResource(resources, R.drawable.enemy02);
        ImageUtil.ImageCacahe.put(ImageUtil.ENEMY_2_KEY, tmp);
        tmp = BitmapFactory.decodeResource(resources, R.drawable.enemy03);
        ImageUtil.ImageCacahe.put(ImageUtil.ENEMY_3_KEY, tmp);
        tmp = BitmapFactory.decodeResource(resources, R.drawable.enemy04);
        ImageUtil.ImageCacahe.put(ImageUtil.ENEMY_4_KEY, tmp);
        tmp = BitmapFactory.decodeResource(resources, R.drawable.enemy05);
        ImageUtil.ImageCacahe.put(ImageUtil.ENEMY_5_KEY, tmp);
        tmp = BitmapFactory.decodeResource(resources, R.drawable.enemy06);
        ImageUtil.ImageCacahe.put(ImageUtil.ENEMY_6_KEY, tmp);
        //加载我方飞机
        tmp = BitmapFactory.decodeResource(resources, R.drawable.player01);
        ImageUtil.ImageCacahe.put(ImageUtil.HERO_1_KEY, tmp);
//        tmp = BitmapFactory.decodeResource(resources, R.drawable.player02);
//        ImageUtil.ImageCacahe.put(ImageUtil.HERO_2_KEY, tmp);
//        tmp = BitmapFactory.decodeResource(resources, R.drawable.player03);
//        ImageUtil.ImageCacahe.put(ImageUtil.HERO_3_KEY, tmp);
//        tmp = BitmapFactory.decodeResource(resources, R.drawable.player04);
//        ImageUtil.ImageCacahe.put(ImageUtil.HERO_4_KEY, tmp);
//        tmp = BitmapFactory.decodeResource(resources, R.drawable.player05);
//        ImageUtil.ImageCacahe.put(ImageUtil.HERO_5_KEY, tmp);
//        tmp = BitmapFactory.decodeResource(resources, R.drawable.player06);
//        ImageUtil.ImageCacahe.put(ImageUtil.HERO_6_KEY, tmp);
        //加载背景
        tmp = BitmapFactory.decodeResource(resources, R.drawable.img_bg_level_1);
        ImageUtil.ImageCacahe.put(ImageUtil.BACK_1_KEY, tmp);
//        tmp = BitmapFactory.decodeResource(resources, R.drawable.img_bg_level_2);
//        ImageUtil.ImageCacahe.put(ImageUtil.BACK_2_KEY, tmp);
//        tmp = BitmapFactory.decodeResource(resources, R.drawable.img_bg_level_3);
//        ImageUtil.ImageCacahe.put(ImageUtil.BACK_3_KEY, tmp);
//        tmp = BitmapFactory.decodeResource(resources, R.drawable.img_bg_level_4);
//        ImageUtil.ImageCacahe.put(ImageUtil.BACK_4_KEY, tmp);
//        tmp = BitmapFactory.decodeResource(resources, R.drawable.img_bg_level_5);
//        ImageUtil.ImageCacahe.put(ImageUtil.BACK_5_KEY, tmp);
        //加载我军子弹
        tmp = BitmapFactory.decodeResource(resources, R.drawable.bul01);
        ImageUtil.ImageCacahe.put(ImageUtil.HERO_BULLET_1_1, tmp);
//        tmp = BitmapFactory.decodeResource(resources, R.drawable.wsparticle_lxfjinjie13);
//        ImageUtil.ImageCacahe.put(ImageUtil.HERO_BULLET_3_1, tmp);
//
//        tmp = BitmapFactory.decodeResource(resources, R.drawable.bul02);
//        ImageUtil.ImageCacahe.put(ImageUtil.HERO_BULLET_2_1, tmp);
//        tmp = BitmapFactory.decodeResource(resources, R.drawable.bul03);
//        ImageUtil.ImageCacahe.put(ImageUtil.HERO_BULLET_2_2, tmp);
//        tmp = BitmapFactory.decodeResource(resources, R.drawable.bul04);
//        ImageUtil.ImageCacahe.put(ImageUtil.HERO_BULLET_2_3, tmp);
//        tmp = BitmapFactory.decodeResource(resources, R.drawable.bul05);
//        ImageUtil.ImageCacahe.put(ImageUtil.HERO_BULLET_2_4, tmp);
//        tmp = BitmapFactory.decodeResource(resources, R.drawable.bul06);
//        ImageUtil.ImageCacahe.put(ImageUtil.HERO_BULLET_2_5, tmp);
//        tmp = BitmapFactory.decodeResource(resources, R.drawable.bul07);
//        ImageUtil.ImageCacahe.put(ImageUtil.HERO_BULLET_2_6, tmp);
//        tmp = BitmapFactory.decodeResource(resources, R.drawable.bul08);
//        ImageUtil.ImageCacahe.put(ImageUtil.HERO_BULLET_2_7, tmp);
//        //跟踪弹
        tmp = BitmapFactory.decodeResource(resources, R.drawable.shotw_0);
        ImageUtil.ImageCacahe.put(ImageUtil.HERO_TRACK_1, tmp);

        //加载敌军子弹
        tmp = BitmapFactory.decodeResource(resources, R.drawable.en_bul02);
        ImageUtil.ImageCacahe.put(ImageUtil.ENEMY_BULLET_1, tmp);

        //旋转的散弹
    }

}
